// TabCtrlEx.cpp : implementation file
//

#include "stdafx.h"
#include "diabetes.h"
#include "TabCtrlEx.h"

#include "FormMainChildDlg14.h"	// Added by ClassView

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTabCtrlEx

CTabCtrlEx::CTabCtrlEx()
{
	m_nNumOfPages = 0;
	m_nCurrentPage = 0;
}

CTabCtrlEx::~CTabCtrlEx()
{
}


BEGIN_MESSAGE_MAP(CTabCtrlEx, CTabCtrl)
	//{{AFX_MSG_MAP(CTabCtrlEx)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTabCtrlEx message handlers

int CTabCtrlEx::GetCurSel()
{
	return CTabCtrl::GetCurSel();
}

int CTabCtrlEx::SetCurSel(int nItem)
{
	if( nItem < 0 || nItem >= m_nNumOfPages)
		return -1;

	int ret = m_nCurrentPage;

	if(m_nCurrentPage != nItem )
	{
		m_nPrePage = m_nCurrentPage;
		m_pPages[m_nCurrentPage]->ShowWindow(SW_HIDE);
		m_nCurrentPage = nItem;
		m_pPages[m_nCurrentPage]->ShowWindow(SW_SHOW);
		CTabCtrl::SetCurSel(nItem);
	}

	return ret;
}

void CTabCtrlEx::Show()
{
	//
	CRect tabRect, itemRect;
	GetClientRect(&tabRect);
	GetItemRect(0, &itemRect);
	int x = tabRect.left;
	int y = tabRect.top;
	int w = tabRect.Width();
	int h = tabRect.Height();
	int xi = itemRect.left;
	int yi = itemRect.top;
	int wi = itemRect.Width();
	int hi = itemRect.Height();
	//
	for( int i=0; i < m_nNumOfPages; i++ )
	{
		m_pPages[i]->Create( m_IDD[i], this );
		InsertItem( i, m_Title[i] );
		m_pPages[i]->ShowWindow(SW_HIDE);
		m_pPages[i]->MoveWindow(tabRect);
	}
	//
	m_pPages[0]->ShowWindow(SW_SHOW);
}

void CTabCtrlEx::SetRect()
{

}

BOOL CTabCtrlEx::AddPage(LPCTSTR title, CDialog *pDialog, UINT ID)
{
	if( MAXPAGE == m_nNumOfPages )
		return FALSE;

	m_nNumOfPages++;

	m_pPages[m_nNumOfPages-1] = pDialog;
	m_IDD[m_nNumOfPages-1] = ID;
	m_Title[m_nNumOfPages-1] = title;

	return TRUE;
}

int CTabCtrlEx::GetPrePage()
{
	return m_nPrePage;
}
